#!/usr/bin/env python2.5

import procpy

def nice_print_by_pid(pid):
   d=procpy.readproc_by_pid(pid)
   print("%-8s %-6d %-7s %s" % (d['ruser'], d['tid'],d['ttynam'],d['cmd']))


def ps_like_print():
   fmt = r"%-10s %-6s %-4s %-4s %-7s  %s %-7s %-7s %s"

   print(fmt % ("USER","PID","%CPU", "%MEM", "TTY", "STAT", "START", "TIME", "COMMAND"))
   for d in procpy.readproc():
      print(fmt % (d['ruser'],
                       str(d['tid']), # int
                           d['pcpustr'],
                           d['pmemstr'],
                           d['ttynam'],
                       str(d['state']), # char->str
              "%02d:%02d"%(d['start'][3], d['start'][4]),
               "%3d:%02d"%(d['time'][0], d['time'][1]),
                  ' '.join(d['cmdline'])))


ps_like_print()
